<template>
    <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px"
             class="demo-ruleForm login-container">
        <h3 class="title">OA系统登录</h3>
        <el-form-item prop="account">
            <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="checkPass">
            <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item prop="captcha">
            <img src="@/assets/captcha.jpg" style="float: left;" ref="captchaImg" @click="imgChange"/>
            <el-input type="text" v-model="ruleForm2.captcha" auto-complete="off" placeholder="验证码"
                      style="width: 230px;float: right"></el-input>
        </el-form-item>
        <el-form-item style="width:100%;">
            <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录
            </el-button>
            <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
        </el-form-item>
    </el-form>
</template>

<script>
    import {login} from "@/api/api";
    export default {
        name: "Login",
        data() {
            return {
                logining: false,
                ruleForm2: {
                    account: '',
                    checkPass: '',
                    captcha: ''
                },
                rules2: {
                    account: [
                        {required: true, message: '请输入账号', trigger: 'blur'},
                        //{ validator: validaePass }
                    ],
                    checkPass: [
                        {required: true, message: '请输入密码', trigger: 'blur'},
                        //{ validator: validaePass2 }
                    ],
                    captcha: [
                        {required: true, message: '请输入验证码', trigger: 'blur'}
                    ]
                },
            };
        },
        methods: {
            imgChange() {
            },

            handleSubmit2() {
                const data={
                    username: this.ruleForm2.account,
                    password: this.ruleForm2.checkPass
                }
                    login(data).then(res => {
                        //自己的业务逻辑代码：服务端返回的参数都封装在了data里面
                        //debugger
                        console.log(res.errcode);
                        console.log(res.errmsg);
                        if (res.errcode==0){
                            /**
                             * sessionStorage 用于临时保存同一窗口(或标签页)的数据，在关闭窗口或标签页之后将会删除这些数据
                             * localStorage的生命周期是永久的，意思就是如果不主动清除，存储的数据将一直被保存
                             */
                            console.log("70====login===登陆成功返回的用户信息")
                            console.log(JSON.stringify(res.data))
                            sessionStorage.setItem('mockUser', JSON.stringify(res.data));
                            //localStorage.setItem('mockUser', JSON.stringify(data));
                            this.$router.push({path: '/chat'});
                        }else {
                            return false;
                        }
                    }).catch(e => {
                        console.log("请求错误");
                        console.log(e);
                        //自己的业务逻辑代码：服务端返回的异常都封装在了e里面
                    });
            }
        }
    }

</script>

<style lang="scss" scoped>
    /**可通过这种方式去修改element-ui样式

    .el-button--primary{
        background-color: #48576a !important;
        border-color: #48576a !important;
    }
    */

    .login-container {
        /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
        -webkit-border-radius: 5px;
        border-radius: 5px;
        -moz-border-radius: 5px;
        background-clip: padding-box;
        margin: 180px auto;
        width: 350px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;

        .title {
            margin: 0px auto 40px auto;
            text-align: center;
            color: #505458;
        }

        .remember {
            margin: 0px 0px 35px 0px;
        }
    }
</style>
